/*
 * @(#) JobItemAction.java Sep 10, 2011
 *
 * Copyright (c) 2011, Strong Technology. All Rights Reserved.
 * Strong Technology. CONFIDENTIAL
 */
package cn.strong.gweva.jobeva.presentation.action;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import cn.strong.gweva.common.business.entity.ComboBoxEntity;
import cn.strong.gweva.common.business.entity.PagerEntity;
import cn.strong.gweva.common.business.service.ComboBoxService;
import cn.strong.gweva.common.presentation.action.AjaxBaseAction;
import cn.strong.gweva.jobeva.business.entity.JobItemEntity;
import cn.strong.gweva.jobeva.business.entity.JobItemExEntity;
import cn.strong.gweva.jobeva.business.entity.JobItemSearchEntity;
import cn.strong.gweva.jobeva.business.service.JobItemService;


/**
 * 岗位考核项目Action.
 * 
 * @author jincong
 * @version 1.0
 * @since Sep 10, 2011
 */
public class JobItemAction extends AjaxBaseAction
{

	/** serialVersionUID */
	private static final long serialVersionUID = 475036766209709765L;

	/** 岗位考核管理service */
	private JobItemService jobItemService;

	/** 下拉框service */
	private ComboBoxService comboBoxService;

	/** 岗位考核项目结果（分页） */
	private PagerEntity pagerEntity;

	/** 岗位考核项目检索entity */
	private JobItemSearchEntity jobItemSearchEntity;

	/** 岗位考核项目管理entity */
	private JobItemEntity jobItemEntity;

	/** 岗位考核项目ID */
	private Integer itemId;

	/** 岗位考核规则长度 */
	private int jobRuleSize;

	/**
	 * 岗位考核项目列表.
	 * 
	 * @return
	 */
	public String list()
	{

		try
		{

			if (this.pagerEntity == null)
			{
				this.pagerEntity = new PagerEntity();
			}
			this.pagerEntity.getPageInfo().setPageSize(new BigDecimal(25));
			this.pagerEntity = this.jobItemService.searchJobItemPage(this.pagerEntity,
					this.jobItemSearchEntity);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return LIST;
	}

	/**
	 * 新增岗位考核项目初始化.
	 * 
	 * @return
	 */
	public String add()
	{
		return ADD;
	}

	/**
	 * 修改岗位考核项目初始化.
	 * 
	 * @return
	 */
	public String modify()
	{
		try
		{

			this.jobItemEntity = this.jobItemService.searchJobItemById(this.itemId);

			if (this.jobItemEntity.getJobRuleList() != null)
			{
				this.jobRuleSize = this.jobItemEntity.getJobRuleList().size();
			}
			else
			{
				this.jobRuleSize = 0;
			}
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return MODIFY;
	}

	/**
	 * 新增岗位考核项目.
	 * 
	 * @return
	 */
	public String insert()
	{

		try
		{

			this.jobItemEntity.getJobItem().setUpdateUserId(this.getLoginUser().getUserId());
			this.jobItemService.insertJobItem(this.jobItemEntity);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return this.list();
	}

	/**
	 * 修改岗位考核项目.
	 * 
	 * @return
	 */
	public String update()
	{

		try
		{

			this.jobItemEntity.getJobItem().setUpdateUserId(this.getLoginUser().getUserId());
			this.jobItemService.updateJobItem(this.jobItemEntity);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return this.list();
	}

	/**
	 * 删除岗位考核项目.
	 * 
	 * @return
	 */
	public String delete()
	{

		try
		{

			this.jobItemEntity = new JobItemEntity();
			JobItemExEntity jobItemExEntity = new JobItemExEntity();
			jobItemExEntity.setItemId(this.itemId);
			this.jobItemEntity.setJobItem(jobItemExEntity);
			this.jobItemEntity.getJobItem().setUpdateUserId(this.getLoginUser().getUserId());
			this.jobItemService.deleteJobItem(this.jobItemEntity);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return this.list();
	}

	/**
	 * 查看岗位考核项目详细.
	 * 
	 * @return
	 */
	public String detail()
	{
		try
		{

			this.jobItemEntity = this.jobItemService.searchJobItemById(this.itemId);
		}
		catch (Exception e)
		{
			return processException(e);
		}

		return DETAIL;
	}

	/**
	 * 设定岗位考核管理service.
	 * 
	 * @param jobItemService 岗位考核管理service
	 */
	public void setJobItemService(JobItemService jobItemService)
	{
		this.jobItemService = jobItemService;
	}

	/**
	 * 获取岗位考核管理service.
	 * 
	 * @return 岗位考核管理service
	 */
	public JobItemService getJobItemService()
	{
		return this.jobItemService;
	}

	/**
	 * 设定下拉框service.
	 * 
	 * @param comboBoxService 下拉框service
	 */
	public void setComboBoxService(ComboBoxService comboBoxService)
	{
		this.comboBoxService = comboBoxService;
	}

	/**
	 * 获取下拉框service.
	 * 
	 * @return 下拉框service
	 */
	public ComboBoxService getComboBoxService()
	{
		return this.comboBoxService;
	}

	/**
	 * 设定岗位考核项目结果（分页）.
	 * 
	 * @param pagerEntity 岗位考核项目结果（分页）
	 */
	public void setPagerEntity(PagerEntity pagerEntity)
	{
		this.pagerEntity = pagerEntity;
	}

	/**
	 * 获取岗位考核项目结果（分页）.
	 * 
	 * @return 岗位考核项目结果（分页）
	 */
	public PagerEntity getPagerEntity()
	{
		return this.pagerEntity;
	}

	/**
	 * 设定岗位考核项目检索entity.
	 * 
	 * @param jobItemSearchEntity 岗位考核项目检索entity
	 */
	public void setJobItemSearchEntity(JobItemSearchEntity jobItemSearchEntity)
	{
		this.jobItemSearchEntity = jobItemSearchEntity;
	}

	/**
	 * 获取岗位考核项目检索entity.
	 * 
	 * @return 岗位考核项目检索entity
	 */
	public JobItemSearchEntity getJobItemSearchEntity()
	{
		return this.jobItemSearchEntity;
	}

	/**
	 * 设定岗位考核项目管理entity.
	 * 
	 * @param jobItemEntity 岗位考核项目管理entity
	 */
	public void setJobItemEntity(JobItemEntity jobItemEntity)
	{
		this.jobItemEntity = jobItemEntity;
	}

	/**
	 * 获取岗位考核项目管理entity.
	 * 
	 * @return 岗位考核项目管理entity
	 */
	public JobItemEntity getJobItemEntity()
	{
		return this.jobItemEntity;
	}

	/**
	 * 设定岗位考核项目ID.
	 * 
	 * @param itemId 岗位考核项目ID
	 */
	public void setItemId(Integer itemId)
	{
		this.itemId = itemId;
	}

	/**
	 * 获取岗位考核项目ID.
	 * 
	 * @return 岗位考核项目ID
	 */
	public Integer getItemId()
	{
		return this.itemId;
	}

	/**
	 * 设定岗位考核规则长度.
	 * 
	 * @param jobRuleSize 岗位考核规则长度
	 */
	public void setJobRuleSize(int jobRuleSize)
	{
		this.jobRuleSize = jobRuleSize;
	}

	/**
	 * 获取岗位考核规则长度.
	 * 
	 * @return 岗位考核规则长度
	 */
	public int getJobRuleSize()
	{
		return this.jobRuleSize;
	}

	/**
	 * 获取岗位列表.
	 * 
	 * @return 岗位列表
	 */
	public List<ComboBoxEntity> getJobList()
	{
		try
		{
			return this.comboBoxService.searchJobList();
		}
		catch (Exception e)
		{

		}

		return new ArrayList<ComboBoxEntity>();
	}

	/**
	 * 获取岗位考核项目列表.
	 * 
	 * @return 岗位考核项目列表
	 */
	public List<ComboBoxEntity> getJobItemList()
	{
		try
		{
			if (this.jobItemEntity != null && this.jobItemEntity.getJobItem() != null
					&& this.jobItemEntity.getJobItem().getJobId() != null)
			{
				return this.comboBoxService.searchJobItemList(this.jobItemEntity.getJobItem()
						.getJobId());
			}
		}
		catch (Exception e)
		{

		}

		return new ArrayList<ComboBoxEntity>();
	}

}
